#pragma once
#include <list>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;


class EpilPointerHelper
{
public:

	template<typename T>
	static void SafeDelete( T* & ptr )
	{
		if( ptr )
		{
			delete ptr;
			ptr = NULL;
		}
	}


	template<typename T>
	static void Delete( const T * ptr )
	{
		if( ptr )
		{
			delete ptr;
		}
	}

	template<typename T>
	static bool Find( const list<T*> & container, const T * item )
	{
		for( list<T*>::const_iterator it = container.begin(); it != container.end(); ++it )
		{
			if( *it == *item )
			{
				return true;
			}
		}
		return false;
	}

	template<typename KeyType, typename ValueType>
	static KeyType * Find( const map<KeyType*, ValueType*> & container, const KeyType * key )
	{
		for( map<KeyType*, ValueType*>::const_iterator it = container.begin(); it != container.end(); ++it )
		{
			if( *it->first == *key )
			{
				return it->second;
			}
		}
		return false;
	}

	template<typename T>
	static void DeleteItemsAndClear( list<T*> & items )
	{
		for_each( items.begin(), items.end(), SafeDelete<T> );
	}

	template<typename T>
	static void DeleteItemsAndClear( vector<T*> & items )
	{
		for_each( items.begin(), items.end(), SafeDelete<T> );
	}

};